package cn.buk.tms.eotms.service;

import cn.buk.common.sc.CommonSearchCriteria;
import cn.buk.tms.eotms.dao.ProductDao;
import cn.buk.tms.eotms.dto.ServiceProductDto;
import cn.buk.tms.eotms.entity.TieInProduct;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yfdai
 */
@Component
public class ProductServiceImpl extends BaseAbstractService implements ProductService {

    @Autowired
    public ProductServiceImpl(ProductDao productDao) {
        this.productDao = productDao;
    }

    private final ProductDao productDao;


  @Override
  public List<ServiceProductDto> searchTieInProducts(final int userId, Integer productType, CommonSearchCriteria sc) {
      final int ownerId = getOwnerIdByUserId(userId);

      List<TieInProduct> products = productDao.searchTieInProducts(ownerId, productType, sc);

      List<ServiceProductDto> dtos = new ArrayList<>();
      for (TieInProduct info : products) {
          ServiceProductDto dto = new ServiceProductDto();
          BeanUtils.copyProperties(info, dto);

          dtos.add(dto);
      }

      return dtos;
  }

}
